/**
 * json配置举例，更多配置请看 IConfigSchema
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { IConfigSchema } from '@/soar';
import { basePath as resourcePath } from './resourceApi';
import { basePath as rulePath } from './ruleApi';
import { basePath as ruleItemPath } from './api';
import { basePath as providePath } from './ruleProvideApi';
import { MenuComponent } from '@/types/interface';
// 获取全部图标的列表

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'spliceType',
    label: '拼接方式',
    dataType: 'dict',
    params: 'SpliceTypeEnum',
    table: {
      width: 80,
    },
  },
  {
    field: 'columnName',
    label: '列名',
    dataType: 'string',
    form: {
      rules: true,
      slots: 'columnName',
    },
  },
  {
    field: 'expression',
    label: '表达式',
    dataType: 'dict',
    params: 'ExpressionEnum',
    form: {
      rules: true,
    },
  },
  {
    field: 'provideType',
    label: '提供方式',
    dataType: 'dict',
    params: 'ProvideTypeEnum',
    table: {
      width: 80,
    },
    form: false,
  },
  {
    field: 'columnValue',
    label: '列值',
    dataType: 'string',
    table: {
      slots: 'columnValue',
    },
    form: {
      vif({ data }) {
        return data.expression < 12;
      },
      slots: 'columnValue',
      rules: true,
    },
  },
];

export default fieldList;

export const resourceSchema: IConfigSchema<any>[] = [
  {
    field: 'code',
    label: '资源编码',
    dataType: 'string',
    form: {
      rules: true,
      slots: 'code',
      formItemProps: {
        tips: '请求路径或 @DataScope 配置的编码',
      },
    },
  },
  {
    field: 'name',
    label: '资源名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'disabled',
    label: '禁用的',
    dataType: 'boolean',
  },
];

export const ruleSchema: IConfigSchema<any>[] = [
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'defaulted',
    label: '缺省的',
    dataType: 'boolean',
    form: {
      disabled({ data }) {
        return data.resourceId === '0';
      },
      formItemProps: {
        tips: '为true时表示：用户未分配有该资源任何规则时默认启用该规则',
      },
    },
  },
];

export const provideSchema: IConfigSchema<any>[] = [
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'className',
    label: 'bean',
    dataType: 'string',
    form: {
      rules: true,
      component: 't-textarea',
      componentProps: {
        placeholder: '类全名 或 bean名称',
      },
    },
  },
  {
    field: 'methodName',
    label: '方法名',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'params',
    label: '参数',
    dataType: 'string',
    form: {
      component: 't-textarea',
    },
  },
];

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '数据权限',
    component: () => import('./List.vue'),
    sort: 60,
    keepalive: true,
    icon: 'chart',
    permits: [
      `GET${resourcePath}/query`,
      `GET${rulePath}/query`,
      `GET${ruleItemPath}/query`,
      `GET${providePath}/query`,
    ],
    elements: [
      { title: '新增资源', code: 'resource/create', permits: [`POST${resourcePath}/create`] },
      {
        title: '更新资源',
        code: 'resource/update',
        permits: [`POST${resourcePath}/update`, `GET${resourcePath}/detail`],
      },
      { title: '删除资源', code: 'resource/remove', permits: [`POST${resourcePath}/remove`] },
      { title: '扫描资源', code: 'resource/scan', permits: [`POST${resourcePath}/scan`] },
      { title: '新增规则', code: 'rule/create', permits: [`POST${rulePath}/create`] },
      { title: '更新规则', code: 'rule/update', permits: [`POST${rulePath}/update`, `GET${rulePath}/detail`] },
      { title: '删除规则', code: 'rule/remove', permits: [`POST${rulePath}/remove`] },
      { title: '新增条件', code: 'rule-item/create', permits: [`POST${ruleItemPath}/create`] },
      {
        title: '更新条件',
        code: 'rule-item/update',
        permits: [`POST${ruleItemPath}/update`, `GET${ruleItemPath}/detail`],
      },
      { title: '删除条件', code: 'rule-item/remove', permits: [`POST${ruleItemPath}/remove`] },
      { title: '新增供应器', code: 'provide/create', permits: [`POST${providePath}/create`] },
      {
        title: '更新供应器',
        code: 'provide/update',
        permits: [`POST${providePath}/update`, `GET${providePath}/detail`],
      },
      { title: '删除供应器', code: 'provide/remove', permits: [`POST${providePath}/remove`] },
      { title: '清空缓存', code: 'clear-cache', permits: [`POST${resourcePath}/clear-cache`] },
    ],
  },
];
